<?php

class Model {

    private $pdo = null;

    private function connect()
    {
        if (!class_exists('PDO', false))
            throw new Exception("PHP PDO package is required.");

        $dsn = TYPE.":host=".HOST.";dbname=".NAME.";charset=".CHARSET;

        try
        {
            $this->pdo = new PDO(
                            $dsn,
                            USER,
                            PASSWORD,
                            array(PDO::ATTR_PERSISTENT => PERSISTENT)
            );
            $this->pdo->exec("SET CHARACTER SET ".CHARSET);
        }
        catch (PDOException $e)
        {
            throw new Exception(sprintf("Can't connect to PDO database '".TYPE."'. Error: %s", $e->getMessage()));
        }

        $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }

    private function close()
    {
        $this->pdo = null;
    }

}
